load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_binary(
    name = "buildifier",
    embed = [":go_default_library"],
    visibility = ["//visibility:public"],
)

go_binary(
    name = "buildifier-darwin",
    out = "buildifier-darwin_amd64",
    embed = [":go_default_library"],
    goarch = "amd64",
    goos = "darwin",
    pure = "on",
    visibility = ["//visibility:public"],
)

go_binary(
    name = "buildifier-linux",
    out = "buildifier-linux_amd64",
    embed = [":go_default_library"],
    goarch = "amd64",
    goos = "linux",
    pure = "on",
    visibility = ["//visibility:public"],
)

go_binary(
    name = "buildifier-windows",
    out = "buildifier-windows_amd64.exe",
    embed = [":go_default_library"],
    goarch = "amd64",
    goos = "windows",
    pure = "on",
    visibility = ["//visibility:public"],
)

# Test that the buildifier binary works
sh_test(
    name = "buildifier_integration_test",
    size = "small",
    srcs = ["integration_test.sh"],
    args = [
        "$(location :buildifier)",
        "$(location //buildifier2)",
    ],
    data = [
        ":buildifier",
        "//buildifier2",
    ],
    deps = ["@bazel_tools//tools/bash/runfiles"],
)

go_library(
    name = "go_default_library",
    srcs = ["buildifier.go"],
    importpath = "github.com/bazelbuild/buildtools/buildifier",
    visibility = ["//visibility:private"],
    x_defs = {
        "main.buildVersion": "{STABLE_buildVersion}",
        "main.buildScmRevision": "{STABLE_buildScmRevision}",
    },
    deps = [
        "//build:go_default_library",
        "//buildifier/utils:go_default_library",
        "//differ:go_default_library",
        "//tables:go_default_library",
        "//warn:go_default_library",
        "//wspace:go_default_library",
    ],
)

exports_files(
    ["runner.bash.template"],
    visibility = ["//visibility:public"],
)

exports_files(
    [
        "README.md",
    ],
    visibility = ["//buildifier/npm:__pkg__"],
)
